Skip to content

fix: improve playback probe reliability for anti-hotlink sources - #220

Open
libertydragonn wants to merge 2 commits into
Decohererk:mainfrom
libertydragonn:redo/playback-probe
Open

fix: improve playback probe reliability for anti-hotlink sources#220
libertydragonn wants to merge 2 commits into
Decohererk:mainfrom
libertydragonn:redo/playback-probe

Conversation

@libertydragonn

Copy link
Copy Markdown
Contributor

背景

重做系列的播放源测速可靠性修复。依赖 SSRF 防护 PR(探测经过 fetchWithValidatedRedirects / validateProxyTargetUrl),在其合并前 diff 会包含那一支的 commit。

改动

  • 对播放清单和媒体分片探测按 URL 派生的 Referer/Origin 和备用 User-Agent 重试,使防盗链源被正确测速,而不是误判为不可用。
  • 代理清单返回 401/403 时,解包同源 m3u8 代理 URL 做仅用于测速的直连校验。
  • 把测速计算的 elapsedMs 以 1ms 为下限,避免亚毫秒读取时 speedKBps 变 undefined(这正是上一轮 review 里 jest --runInBand 偶发失败的根因);新增冻结时钟的回归测试覆盖同毫秒读取路径。

验证

  • jest --runInBand 通过(20 套件 / 108 测试;连续多次运行稳定,无偶发失败)
  • pnpm typecheck 通过
  • docker build 本分支镜像成功

不改动登录 / 鉴权流程。

- New src/lib/proxy-security.ts: validateProxyTargetUrl blocks localhost,
  private/link-local/CGNAT ranges, cloud metadata hosts and credentialed
  URLs, resolves DNS and rejects targets answering with blocked addresses;
  fetchWithValidatedRedirects re-validates every redirect hop.
- Opt-in allowlisting for self-hosted LAN media (NAS/Jellyfin) via
  PROXY_ALLOW_PRIVATE_HOSTS=true + PROXY_PRIVATE_HOST_ALLOWLIST
  (exact IPs, hostnames, IPv4 CIDRs).
- Apply validation to /api/proxy/{cms,key,logo,m3u8,segment,stream},
  /api/download/{proxy,ffmpeg,ffmpeg/file}, /api/live/precheck and
  /api/douban/health.
- Documented threat model: this significantly reduces SSRF exposure but
  resolved IPs are not pinned to the socket, so DNS rebinding is
  mitigated best-effort, not eliminated.
- Add proxy target validation regression tests.

No auth/cookie/middleware changes in this PR.
- Retry playlist and media probes with URL-derived Referer/Origin and
  alternate User-Agent headers so sources that reject bare requests are
  measured correctly instead of being misreported as dead.
- Unwrap same-origin m3u8 proxy URLs for measurement-only direct checks
  when the proxied manifest returns 401/403.
- Clamp the speed calculation to a 1ms minimum elapsed time so
  sub-millisecond reads never yield an undefined speed (this was the
  flaky jest failure in the previous review round); add a frozen-clock
  regression test for the same-millisecond read path.
- Probe fetches validate targets and redirects via proxy-security.

Depends on the proxy-security PR. No auth changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant